-
Notifications
You must be signed in to change notification settings - Fork 33
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
UX improvements: FFI logging, error message fix, Rust stream borrow checks #515
Conversation
PR Review ChecklistDo not edit the content of this comment. The PR reviewer should simply update this comment by ticking each review item below, as they get completed. Trivial Change
Code
Architecture
|
429ca6e
to
616bec2
Compare
@@ -180,6 +180,7 @@ test_for_each_arg! { | |||
let age = unwrap_long(age?.map.remove("age").unwrap()); | |||
assert_eq!(age, 1); | |||
} | |||
drop(ages); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
ages
(a Stream
) now borrows the transaction
let answer = context.transaction().query().get(&parsed.to_string())?.try_collect::<Vec<_>>().await?; | ||
context.answer = answer; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We should be able to write this on one line, but the borrow checker gets confused by the .await
, and thinks that we attempt to borrow context
twice at the same time.
break collector | ||
.close(ConnectionError::TransactionIsClosedWithErrors(err.message().to_owned())) | ||
.await |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Use the correct error message rather than Status::to_string()
@Nullable | ||
private final com.vaticle.typedb.driver.jni.Error nativeError; | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We no longer store the native error and instead just take its message.
#[no_mangle] | ||
pub extern "C" fn init_logging() { | ||
const ENV_VAR: &str = "TYPEDB_DRIVER_LOG_LEVEL"; | ||
if let Err(err) = env_logger::try_init_from_env(Env::new().filter(ENV_VAR)) { | ||
warn!("{err}"); | ||
} | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This function allows the FFI drivers to initialize the Rust logger. (Rust driver users can do this directly)
…hecks (typedb#515) ## What is the goal of this PR? We improve the UX of Driver usage in several ways: - [Rust/Java/Python] Fix the formatting of error messages received from the server during a transaction. - [Java] Fix native error message formatting. - [Java/Python] Add the ability to enable Rust logging over FFI (resolves typedb#482). - The granularity of the logs is controlled by the `TYPEDB_DRIVER_LOG_LEVEL` environment variable, which can be set to any value of `error` (default), `warn`, `info`, `debug`, or `trace`, in order of increasing verbosity. Setting the value to `"typedb_driver=info"` will show only the typedb-driver messages. - More advanced syntax is described in [the env_logger documentation](https://docs.rs/env_logger/latest/env_logger/index.html#enabling-logging) - [Rust] Network streams now borrow the transaction, so that the transaction can't be mistakenly dropped. (resolves typedb#449)
What is the goal of this PR?
We improve the UX of Driver usage in several ways:
TYPEDB_DRIVER_LOG_LEVEL
environment variable, which can be set to any value oferror
(default),warn
,info
,debug
, ortrace
, in order of increasing verbosity. Setting the value to"typedb_driver=info"
will show only the typedb-driver messages.